//
//  SERegistrationDetailCell.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/4/7.
//

import UIKit

enum SERegistrationDetailCellStatus: Int {
    case cancel = 0
    case success

    var statusLabelText: String {
        switch self {
        case .cancel: return "已取消"
        case .success: return "预约成功, 等待就诊"
        }
    }

    var statusLabelTextColor: UIColor {
        switch self {
        case .cancel:  return Asset.textGrayLightest.color
        case .success: return Asset.main.color
        }
    }

    func memoLabeltextColor(_ isFee: Bool = false) -> UIColor {
        switch self {
        case .cancel:
            return Asset.textGrayLightest.color
        case .success:
            if isFee {
                return UIColor(hex: "#F3B446")
            } else {
                return Asset.textDark.color
            }
        }
    }

    var titleLabeltextColor: UIColor {
        switch self {
        case .cancel:
            return Asset.textGrayLightest.color
        case .success:
            return Asset.textLight.color
        }
    }

}

class SERegistrationDetailCell: UITableViewCell {

    static let className = "SERegistrationDetailCell"
    static let reuseId = className



    @IBOutlet weak var departmentTitleLabel: UILabel!
    @IBOutlet weak var doctorNameTitleLabel: UILabel!
    @IBOutlet weak var dateTitleLabel: UILabel!
    @IBOutlet weak var timeTitleLabel: UILabel!
    @IBOutlet weak var feeTitleLabel: UILabel!
    @IBOutlet weak var patientNameTitleLabel: UILabel!

    @IBOutlet weak var statusLabel: UILabel!

    @IBOutlet weak var departmentLabel: UILabel!
    @IBOutlet weak var doctorNameLabel: UILabel!
    @IBOutlet weak var dateLabel: UILabel!
    @IBOutlet weak var timeLabel: UILabel!
    @IBOutlet weak var feeLabel: UILabel!
    @IBOutlet weak var patientNameLabel: UILabel!

    var status: SERegistrationDetailCellStatus = .cancel {
        didSet {
            statusLabel.text = status.statusLabelText
            statusLabel.textColor = status.statusLabelTextColor

            departmentLabel.textColor = status.memoLabeltextColor()
            doctorNameLabel.textColor = status.memoLabeltextColor()
            dateLabel.textColor = status.memoLabeltextColor()
            timeLabel.textColor = status.memoLabeltextColor()
            feeLabel.textColor = status.memoLabeltextColor(true)
            patientNameLabel.textColor = status.memoLabeltextColor()

            departmentTitleLabel.textColor = status.memoLabeltextColor()
            doctorNameTitleLabel.textColor = status.memoLabeltextColor()
            dateTitleLabel.textColor = status.memoLabeltextColor()
            timeTitleLabel.textColor = status.memoLabeltextColor()
            feeTitleLabel.textColor = status.memoLabeltextColor()
            patientNameTitleLabel.textColor = status.memoLabeltextColor()
        }
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    func updateCell(model: SEMyRegistrationModel) {
        self.status = SERegistrationDetailCellStatus(rawValue: model.flag) ?? .cancel
        departmentLabel.text = model.deptName
        doctorNameLabel.text = model.doctorName
        dateLabel.text = "\(model.diagDate) \(model.week) \(model.registerPeriod)"
        timeLabel.text = "序号\(model.number) \(model.diagTime)"
        patientNameLabel.text = model.patientName
        feeLabel.text = model.fee
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
